package com.xiaoxing.gongqiju.mvp.ui.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.hss01248.frescopicker.FrescoIniter;
import com.hss01248.photoouter.PhotoCallback;
import com.hss01248.photoouter.PhotoUtil;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.base.BaseConstants;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.xiaoxing.gongqiju.R;
import com.xiaoxing.gongqiju.R2;
import com.xiaoxing.gongqiju.di.component.DaggerLiaoCheng_GongQiJu_GuiHuanCaoZuoComponent;
import com.xiaoxing.gongqiju.di.module.LiaoCheng_GongQiJu_GuiHuanCaoZuoModule;
import com.xiaoxing.gongqiju.mvp.contract.LiaoCheng_GongQiJu_GuiHuanCaoZuoContract;
import com.xiaoxing.gongqiju.mvp.presenter.LiaoCheng_GongQiJu_GuiHuanCaoZuoPresenter;
import com.xiaoxing.gongqiju.mvp.ui.adapter.LiaoCheng_GongQiJu_GuiHuanCaoZuoAdapter;
import com.xiaoxing.gongqiju.mvp.ui.entity.LiaoCheng_GongQiJu_GuiHuanCaoZuo;
import com.xiaoxing.gongqiju.mvp.ui.entity.RepairGongJu;
import com.xiaoxing.gongqiju.mvp.ui.entity.ReturnGongJu;
import com.xiaoxing.gongqiju.mvp.ui.entity.ReturnRepair;
import com.xw.repo.XEditText;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import me.iwf.photopicker.utils.ProxyTools;
import me.jessyan.armscomponent.commonres.utils.BottomDialogUtil;
import com.jess.arms.utils.CProgressDialogUtils;
import me.jessyan.armscomponent.commonres.utils.ToolbarUtils;
import me.jessyan.armscomponent.commonres.view.RecycleViewDivider;
import me.jessyan.armscomponent.commonsdk.core.RouterHub;
import me.jessyan.armscomponent.commonsdk.utils.ButtonUtils;
import okhttp3.RequestBody;

import static com.jess.arms.base.BaseConstants.SCAN_REQUEST_CODE;
import static com.jess.arms.utils.Preconditions.checkNotNull;


@Route(path = RouterHub.GONGQIJU_LIAOCHENG_ACTIVITY_LIAO_CHENG_GONG_QI_JU_GUI_HUAN_CAO_ZUO)
public class LiaoCheng_GongQiJu_GuiHuanCaoZuoActivity extends BaseActivity<LiaoCheng_GongQiJu_GuiHuanCaoZuoPresenter> implements LiaoCheng_GongQiJu_GuiHuanCaoZuoContract.View, OnRefreshListener, LiaoCheng_GongQiJu_GuiHuanCaoZuoAdapter.ILiaoCheng_GongQiJu_GuiHuanCaoZuoAdapter {


    private static boolean mIsNeedDemo = true;
    @BindView(R2.id.empty_text)
    TextView empty_text;
    @BindView(R2.id.empty_image)
    ImageView empty_image;

    @BindView(R2.id.empty)
    View mEmptyLayout;
    @BindView(R2.id.recyclerView)
    RecyclerView mRecyclerView;
    @BindView(R2.id.refreshLayout)
    RefreshLayout mRefreshLayout;
    private LiaoCheng_GongQiJu_GuiHuanCaoZuoAdapter mAdapter;
    private List<LiaoCheng_GongQiJu_GuiHuanCaoZuo.DataBean> mDataBeanList = new ArrayList<>();
    private String mtid;
    private String materialCodeMode;
    private String scanResult;
    private int mCurrentDialogStyle = com.qmuiteam.qmui.R.style.QMUI_Dialog;

    private String mGuiHuanPic = "";
    private String mWeiXiuPic = "";
    private LiaoCheng_GongQiJu_GuiHuanCaoZuo.DataBean item;
    private BottomDialogUtil mBottomDialogUtilShare;
    private AlertDialog mAlertDialog;
    private String mGuiHuanYuWeiXiuPic = "";
    private String mCaoZuoMid = "";

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerLiaoCheng_GongQiJu_GuiHuanCaoZuoComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .liaoCheng_GongQiJu_GuiHuanCaoZuoModule(new LiaoCheng_GongQiJu_GuiHuanCaoZuoModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_liao_cheng__gong_qi_ju__gui_huan_cao_zuo; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        ToolbarUtils.initToolbarTitleBack(this, getString(R.string.activity_liao_cheng__gong_qi_ju__gui_huan_cao_zuo));
        PhotoUtil.init(this, new FrescoIniter());

        mtid = getIntent().getExtras().getString("mtid");
        materialCodeMode = getIntent().getExtras().getString("materialCodeMode");
        initRefreshLayout();
        initRecyclerView();
        initEmpty();
        getLiaoCheng_GongQiJu_GuiHuanCaoZuoList();

    }

    private void initEmpty() {
        empty_image.setImageResource(R.drawable.ic_empty);
        empty_text.setTextColor(Color.parseColor("#D8D8D8"));
        empty_text.setText("暂无数据");
    }

    private List<LiaoCheng_GongQiJu_GuiHuanCaoZuo.DataBean> loadModels() {
        List<LiaoCheng_GongQiJu_GuiHuanCaoZuo.DataBean> lists = new ArrayList<>();

        for (int i = 0; i < 5; i++) {

            LiaoCheng_GongQiJu_GuiHuanCaoZuo.DataBean dataBean = new LiaoCheng_GongQiJu_GuiHuanCaoZuo.DataBean();
            lists.add(dataBean);
        }

        return lists;
    }

    private void initRecyclerView() {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(LiaoCheng_GongQiJu_GuiHuanCaoZuoActivity.this));
        mRecyclerView.addItemDecoration(new RecycleViewDivider(this, LinearLayoutManager.VERTICAL, 10, Color.parseColor("#EEEEEE")));

        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setAdapter(mAdapter = new LiaoCheng_GongQiJu_GuiHuanCaoZuoAdapter(LiaoCheng_GongQiJu_GuiHuanCaoZuoActivity.this, mDataBeanList, this, materialCodeMode));

        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
            }
        });
    }

    private void initRefreshLayout() {
        mRefreshLayout.setRefreshHeader(new
                ClassicsHeader(this).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.public_colorPrimary).setAccentColorId(android.R.color.white));
        mRefreshLayout.setOnRefreshListener(this);
        mRefreshLayout.setEnableRefresh(false);
        mRefreshLayout.autoRefresh();
        mRefreshLayout.setEnableLoadMore(false);
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

        //getLiaoCheng_GongQiJu_GuiHuanCaoZuoList();
        mRefreshLayout.finishRefresh();
        mEmptyLayout.setVisibility(View.GONE);

    }

    @Override
    public void getLiaoCheng_GongQiJu_GuiHuanCaoZuoDataSuccess(LiaoCheng_GongQiJu_GuiHuanCaoZuo entityList) {

        if (entityList != null && entityList.getData() != null && entityList.getData().size() > 0) {
            mDataBeanList.clear();
            mDataBeanList.addAll(entityList.getData());
            mAdapter.notifyDataSetChanged();
            mEmptyLayout.setVisibility(View.GONE);
            mRecyclerView.setVisibility(View.VISIBLE);
        } else {
            mEmptyLayout.setVisibility(View.VISIBLE);
            mRecyclerView.setVisibility(View.GONE);
        }

    }

    private void clearData() {
        mDataBeanList.clear();
        mAdapter.notifyDataSetChanged();
        mEmptyLayout.setVisibility(View.VISIBLE);
        mRecyclerView.setVisibility(View.GONE);
    }

    private void getLiaoCheng_GongQiJu_GuiHuanCaoZuoList() {
        HashMap<String, String> map = new HashMap<>();
        map.put("mtid", mtid);
        mPresenter.getLiaoCheng_GongQiJu_GuiHuanCaoZuoList(map);
    }

    @Override
    public void showLoading() {
        CProgressDialogUtils.showProgressDialog(this);
    }

    @Override
    public void hideLoading() {
        CProgressDialogUtils.cancelProgressDialog(this);
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.makeText(this, message);

    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public void saoMiaoErWerMa(LiaoCheng_GongQiJu_GuiHuanCaoZuo.DataBean item) {
        this.item = null;
        this.item = item;
        mCaoZuoMid = item.getMid();
        toScanQRCodeActivity();
    }

    @Override
    public void guiHuan(LiaoCheng_GongQiJu_GuiHuanCaoZuo.DataBean item) {

        showGuiHuanDialog(item);
    }

    /**
     * @param
     * @return
     * @method
     * @description 弹出归还，维修，需要填写归还数量和维修数量，有就填写，可以为空
     * @date: 2020/9/3 0003 16:46
     * @author: 小星
     */
    private void showGuiHuanDialog(LiaoCheng_GongQiJu_GuiHuanCaoZuo.DataBean item) {


        View myView = LayoutInflater.from(this).inflate(R.layout.layout_gui_huan_wei_xiu, null);
        XEditText xet_gui_huan_shu_liang = myView.findViewById(R.id.xet_gui_huan_shu_liang);
        XEditText xet_wei_xiu_shu_liang = myView.findViewById(R.id.xet_wei_xiu_shu_liang);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setPositiveButton("归还", null);
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });

        mAlertDialog = builder.create();
        mAlertDialog.setTitle("归还操作");
        mAlertDialog.setView(myView);
        mAlertDialog.show();


        //拿到按钮并判断是否是POSITIVEBUTTON，然后我们自己实现监听
        mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!ButtonUtils.isFastDoubleClick()) {
                    String guiHuanShuLiang = xet_gui_huan_shu_liang.getText().toString().trim();
                    String weiXiuShuLiang = xet_wei_xiu_shu_liang.getText().toString().trim();
                    if (TextUtils.isEmpty(guiHuanShuLiang) && TextUtils.isEmpty(weiXiuShuLiang)) {
                        showMessage("归还数量、维修数量必须填写一个");
                    } else {

                        if (TextUtils.isEmpty(mGuiHuanYuWeiXiuPic)) {
                            showMessage("请先拍照");
                            xuanZeGuiHuanYuWeiXiuTuPian();
                        } else {

                            if ((Double.parseDouble((guiHuanShuLiang.length() > 0 ? guiHuanShuLiang : "0")) + Double.parseDouble((weiXiuShuLiang.length() > 0 ? weiXiuShuLiang : "0"))) <= Double.parseDouble(item.getOutNum())) {
                                returnRepair(guiHuanShuLiang, weiXiuShuLiang, item);
                                mAlertDialog.dismiss();
                            } else {
                                showMessage("归还数量与维修数量之和不能大于" + item.getOutNum());
                            }
                        }

                    }

                } else {
                    showMessage("10s内请勿重复点击");
                }

            }
        });


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == 101) {
            Bundle bundle = data.getExtras();
            scanResult = bundle.getString("scan_result");
            if (!TextUtils.isEmpty(mCaoZuoMid) && !TextUtils.isEmpty(scanResult) && mCaoZuoMid.equals(scanResult)) {
                showWeiXiuMessageNegativeDialog();
            } else {
                showMessage("扫描的物料和当前操作的物料不是一个，请重新扫描。扫描的数据是：" + scanResult + " 操作的数据是：" + mCaoZuoMid);
                mCaoZuoMid = "";
                scanResult = "";
            }
        } else {
            if (resultCode != 0)
                PhotoUtil.onActivityResult(this, requestCode, resultCode, data);
        }

    }

    private void showWeiXiuMessageNegativeDialog() {
        new QMUIDialog.MessageDialogBuilder(this)
                .setTitle("确认")
                .setMessage("请放入" + this.item.getSpname() + "上 " + this.item.getOutNum() + "数量")
                .addAction("取消", new QMUIDialogAction.ActionListener() {
                    @Override
                    public void onClick(QMUIDialog dialog, int index) {
                        dialog.dismiss();
                    }
                })
                .addAction(0, "维修", QMUIDialogAction.ACTION_PROP_NEUTRAL, new QMUIDialogAction.ActionListener() {
                    @Override
                    public void onClick(QMUIDialog dialog, int index) {
                        if (!TextUtils.isEmpty(mWeiXiuPic)) {
                            repairGongJu(item);
                            dialog.dismiss();
                        } else {
                            showMessage("请先拍照");
                            xuanZeWeiXiuTuPian();
                        }


                    }
                }).addAction(0, "确定归还", QMUIDialogAction.ACTION_PROP_NEGATIVE, new QMUIDialogAction.ActionListener() {
            @Override
            public void onClick(QMUIDialog dialog, int index) {
                if (!TextUtils.isEmpty(mGuiHuanPic)) {
                    returnGongJu(item);
                    dialog.dismiss();
                } else {
                    showMessage("请先拍照");
                    xuanZeGuiHuanTuPian();
                }

            }
        }).create(mCurrentDialogStyle).show();
    }

    @Override
    public void returnGongJuDataSuccess(ReturnGongJu entityList) {
        showMessage(entityList.getMessage());
        if (entityList.getCode().equals("200")) {
            mGuiHuanPic = "";
            clearData();
            getLiaoCheng_GongQiJu_GuiHuanCaoZuoList();
        }
    }

    private void returnGongJu(LiaoCheng_GongQiJu_GuiHuanCaoZuo.DataBean itemData) {

        String item = "";

        item += " {\n" +
                "    \"rid\": " + "" + ",\n" +
                "    \"mid\": " + itemData.getMid() + ",\n" +
                "    \"oid\": " + itemData.getOid() + ",\n" +
                "    \"spid\": " + itemData.getSpid() + ",\n" +
                "    \"picId\": " + "" + ",\n" +
                "    \"returnuserid\": " + mSharedPreferencesHelper.getString(BaseConstants.UID) + ",\n" +
                "    \"ReturnNum\": " + itemData.getOutNum() + ",\n" +
                "    \"returntime\": \"" + ArmsUtils.getDataTime("yyyy-MM-dd HH:mm:ss") + "\",\n" +
                "    \"Pictures\": [\n" +
                "      {\n" +
                "        \"PictureId\": 0,\n" +
                "        \"PictureExtension\": \"jpg\",\n" +
                "        \"Picture\": \"" + mGuiHuanPic + "\"\n" +
                "      }\n" +
                "    ]\n" +
                "  },";


        String jsonData = "[" + ArmsUtils.cutLastString(item) + "]";
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), jsonData);

        mPresenter.returnGongJu(body);
    }

    private void xuanZeGuiHuanTuPian() {
        LinearLayout root = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.sales_client_bottom_dialog_pai_zhao, null);
        Button btn_xiang_ce = root.findViewById(me.iwf.photopicker.R.id.btn_xiang_ce);
        Button ben_xiang_ji = root.findViewById(me.iwf.photopicker.R.id.ben_xiang_ji);
        Button btn_qu_xiao = root.findViewById(me.iwf.photopicker.R.id.btn_qu_xiao);
        btn_qu_xiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mBottomDialogUtilShare != null)
                    mBottomDialogUtilShare.dismissDiaolog();
            }
        });
        btn_xiang_ce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mBottomDialogUtilShare != null)
                    mBottomDialogUtilShare.dismissDiaolog();

                PhotoUtil.begin()
                        .setNeedCropWhenOne(false)
                        .setNeedCompress(false)
                        .setMaxSelectCount(1)

                        .start(LiaoCheng_GongQiJu_GuiHuanCaoZuoActivity.this, 33, ProxyTools.getShowMethodInfoProxy(new PhotoCallback() {
                            @Override
                            public void onFail(String msg, Throwable r, int requestCode) {
                            }

                            @Override
                            public void onSuccessSingle(String originalPath, String compressedPath, int requestCode) {
//
                                try {
                                    mGuiHuanPic = ArmsUtils.bitmapToString(compressedPath);
                                    showMessage("选择照片成功，请再点击归还按钮，进行归还操作！");
//                                    Bitmap bitmap = BitmapFactory.decodeFile(compressedPath);
//                                    imgZhaoPian.setImageBitmap(bitmap);
                                } catch (Exception e) {
                                    e.printStackTrace();

                                }
                            }

                            @Override
                            public void onSuccessMulti(List<String> originalPaths, List<String> compressedPaths, int requestCode) {
//                                refresh1(originalPaths);

                            }

                            @Override
                            public void onCancel(int requestCode) {
                            }
                        }));
            }
        });
        ben_xiang_ji.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mBottomDialogUtilShare != null)
                    mBottomDialogUtilShare.dismissDiaolog();
                PhotoUtil.statusBarColor = R.color.public_black;
                PhotoUtil.titleBarColor = R.color.public_black;
                PhotoUtil.cropAvatar(true).setCropMuskOvalFalse()
                        .start(LiaoCheng_GongQiJu_GuiHuanCaoZuoActivity.this, 23, ProxyTools.getShowMethodInfoProxy(new PhotoCallback() {
                            @Override
                            public void onFail(String msg, Throwable r, int requestCode) {
                            }

                            @Override
                            public void onSuccessSingle(String originalPath, String compressedPath, int requestCode) {
                                try {
                                    mGuiHuanPic = ArmsUtils.bitmapToString(compressedPath);
                                    showMessage("拍照成功，请再点击归还按钮，进行归还操作！");
//                                    Bitmap bitmap = BitmapFactory.decodeFile(compressedPath);
//                                    imgZhaoPian.setImageBitmap(bitmap);
                                } catch (Exception e) {
                                    e.printStackTrace();

                                }
                            }

                            @Override
                            public void onSuccessMulti(List<String> originalPaths, List<String> compressedPaths, int requestCode) {
                            }

                            @Override
                            public void onCancel(int requestCode) {
                            }
                        }));
            }
        });

        mBottomDialogUtilShare = new BottomDialogUtil(LiaoCheng_GongQiJu_GuiHuanCaoZuoActivity.this, root);
        mBottomDialogUtilShare.showDiaolog();

    }

    private void xuanZeWeiXiuTuPian() {
        LinearLayout root = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.sales_client_bottom_dialog_pai_zhao, null);
        Button btn_xiang_ce = root.findViewById(me.iwf.photopicker.R.id.btn_xiang_ce);
        Button ben_xiang_ji = root.findViewById(me.iwf.photopicker.R.id.ben_xiang_ji);
        Button btn_qu_xiao = root.findViewById(me.iwf.photopicker.R.id.btn_qu_xiao);
        btn_qu_xiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mBottomDialogUtilShare != null)
                    mBottomDialogUtilShare.dismissDiaolog();
            }
        });
        btn_xiang_ce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mBottomDialogUtilShare != null)
                    mBottomDialogUtilShare.dismissDiaolog();

                PhotoUtil.begin()
                        .setNeedCropWhenOne(false)
                        .setNeedCompress(false)
                        .setMaxSelectCount(1)

                        .start(LiaoCheng_GongQiJu_GuiHuanCaoZuoActivity.this, 33, ProxyTools.getShowMethodInfoProxy(new PhotoCallback() {
                            @Override
                            public void onFail(String msg, Throwable r, int requestCode) {
                            }

                            @Override
                            public void onSuccessSingle(String originalPath, String compressedPath, int requestCode) {
//
                                try {
                                    mWeiXiuPic = ArmsUtils.bitmapToString(compressedPath);
                                    showMessage("选择照片成功，请再点击维修按钮，进行维修操作！");
//                                    Bitmap bitmap = BitmapFactory.decodeFile(compressedPath);
//                                    imgZhaoPian.setImageBitmap(bitmap);
                                } catch (Exception e) {
                                    e.printStackTrace();

                                }
                            }

                            @Override
                            public void onSuccessMulti(List<String> originalPaths, List<String> compressedPaths, int requestCode) {
//                                refresh1(originalPaths);

                            }

                            @Override
                            public void onCancel(int requestCode) {
                            }
                        }));
            }
        });
        ben_xiang_ji.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mBottomDialogUtilShare != null)
                    mBottomDialogUtilShare.dismissDiaolog();
                PhotoUtil.statusBarColor = R.color.public_black;
                PhotoUtil.titleBarColor = R.color.public_black;
                PhotoUtil.cropAvatar(true).setCropMuskOvalFalse()
                        .start(LiaoCheng_GongQiJu_GuiHuanCaoZuoActivity.this, 23, ProxyTools.getShowMethodInfoProxy(new PhotoCallback() {
                            @Override
                            public void onFail(String msg, Throwable r, int requestCode) {
                            }

                            @Override
                            public void onSuccessSingle(String originalPath, String compressedPath, int requestCode) {
                                try {
                                    mWeiXiuPic = ArmsUtils.bitmapToString(compressedPath);
                                    showMessage("拍照成功，请再点击维修按钮，进行维修操作！");
//                                    Bitmap bitmap = BitmapFactory.decodeFile(compressedPath);
//                                    imgZhaoPian.setImageBitmap(bitmap);
                                } catch (Exception e) {
                                    e.printStackTrace();

                                }
                            }

                            @Override
                            public void onSuccessMulti(List<String> originalPaths, List<String> compressedPaths, int requestCode) {
                            }

                            @Override
                            public void onCancel(int requestCode) {
                            }
                        }));
            }
        });

        mBottomDialogUtilShare = new BottomDialogUtil(LiaoCheng_GongQiJu_GuiHuanCaoZuoActivity.this, root);
        mBottomDialogUtilShare.showDiaolog();

    }

    private void xuanZeGuiHuanYuWeiXiuTuPian() {
        LinearLayout root = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.sales_client_bottom_dialog_pai_zhao, null);
        Button btn_xiang_ce = root.findViewById(me.iwf.photopicker.R.id.btn_xiang_ce);
        Button ben_xiang_ji = root.findViewById(me.iwf.photopicker.R.id.ben_xiang_ji);
        Button btn_qu_xiao = root.findViewById(me.iwf.photopicker.R.id.btn_qu_xiao);
        btn_qu_xiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mBottomDialogUtilShare != null)
                    mBottomDialogUtilShare.dismissDiaolog();
            }
        });
        btn_xiang_ce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mBottomDialogUtilShare != null)
                    mBottomDialogUtilShare.dismissDiaolog();

                PhotoUtil.begin()
                        .setNeedCropWhenOne(false)
                        .setNeedCompress(false)
                        .setMaxSelectCount(1)

                        .start(LiaoCheng_GongQiJu_GuiHuanCaoZuoActivity.this, 33, ProxyTools.getShowMethodInfoProxy(new PhotoCallback() {
                            @Override
                            public void onFail(String msg, Throwable r, int requestCode) {
                            }

                            @Override
                            public void onSuccessSingle(String originalPath, String compressedPath, int requestCode) {
//
                                try {
                                    mGuiHuanYuWeiXiuPic = ArmsUtils.bitmapToString(compressedPath);
                                    showMessage("选择照片成功，请再点击归还按钮，进行归还操作！");
//                                    Bitmap bitmap = BitmapFactory.decodeFile(compressedPath);
//                                    imgZhaoPian.setImageBitmap(bitmap);
                                } catch (Exception e) {
                                    e.printStackTrace();

                                }
                            }

                            @Override
                            public void onSuccessMulti(List<String> originalPaths, List<String> compressedPaths, int requestCode) {
//                                refresh1(originalPaths);

                            }

                            @Override
                            public void onCancel(int requestCode) {
                            }
                        }));
            }
        });
        ben_xiang_ji.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mBottomDialogUtilShare != null)
                    mBottomDialogUtilShare.dismissDiaolog();
                PhotoUtil.statusBarColor = R.color.public_black;
                PhotoUtil.titleBarColor = R.color.public_black;
                PhotoUtil.cropAvatar(true).setCropMuskOvalFalse()
                        .start(LiaoCheng_GongQiJu_GuiHuanCaoZuoActivity.this, 23, ProxyTools.getShowMethodInfoProxy(new PhotoCallback() {
                            @Override
                            public void onFail(String msg, Throwable r, int requestCode) {
                            }

                            @Override
                            public void onSuccessSingle(String originalPath, String compressedPath, int requestCode) {
                                try {
                                    mGuiHuanYuWeiXiuPic = ArmsUtils.bitmapToString(compressedPath);
                                    showMessage("选择照片成功，请再点击归还按钮，进行归还操作！");
//                                    Bitmap bitmap = BitmapFactory.decodeFile(compressedPath);
//                                    imgZhaoPian.setImageBitmap(bitmap);
                                } catch (Exception e) {
                                    e.printStackTrace();

                                }
                            }

                            @Override
                            public void onSuccessMulti(List<String> originalPaths, List<String> compressedPaths, int requestCode) {
                            }

                            @Override
                            public void onCancel(int requestCode) {
                            }
                        }));
            }
        });

        mBottomDialogUtilShare = new BottomDialogUtil(LiaoCheng_GongQiJu_GuiHuanCaoZuoActivity.this, root);
        mBottomDialogUtilShare.showDiaolog();

    }

    private void repairGongJu(LiaoCheng_GongQiJu_GuiHuanCaoZuo.DataBean itemData) {

        String item = "";

        item += "{\n" +
                "    \"mrid\": " + "" + ",\n" +
                "    \"mid\": " + itemData.getMid() + ",\n" +
                "    \"oid\": " + itemData.getOid() + ",\n" +
                "    \"remark\": \"" + "" + "\",\n" +
                "    \"repairtype\": 2,\n" +
                "    \"repairuserid\": " + mSharedPreferencesHelper.getString(BaseConstants.UID) + ",\n" +
                "    \"repairstatus\": 0,\n" +
                "    \"repairtime\": \"" + ArmsUtils.getDataTime("yyyy-MM-dd HH:mm:ss") + "\",\n" +
                "    \"picId\": 0,\n" +
                "    \"Num\": " + itemData.getOutNum() + ",\n" +
                "    \"Pictures\": [\n" +
                "      {\n" +
                "        \"PictureId\": 0,\n" +
                "        \"PictureExtension\": \"jpg\",\n" +
                "        \"Picture\": \"" + mWeiXiuPic + "\"\n" +
                "      }\n" +
                "    ]\n" +
                "  },";


        String jsonData = "[" + ArmsUtils.cutLastString(item) + " ]";
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), jsonData);

        mPresenter.repairGongJu(body);
    }

    private void returnRepair(String guiHuanShuLiang, String weiXiuShuLiang, LiaoCheng_GongQiJu_GuiHuanCaoZuo.DataBean itemData) {
        String strWeiXiu = "";
        if (Double.parseDouble((weiXiuShuLiang.length() > 0 ? weiXiuShuLiang : "0")) > 0) {
            strWeiXiu += "\n" +
                    "    {\n" +
                    "      \"mrid\": " + "" + ",\n" +
                    "      \"mid\": " + itemData.getMid() + ",\n" +
                    "      \"oid\": " + itemData.getOid() + ",\n" +
                    "      \"remark\": \"" + "" + "\",\n" +
                    "      \"repairtype\": 2,\n" +
                    "      \"repairuserid\": " + mSharedPreferencesHelper.getString(BaseConstants.UID) + ",\n" +
                    "      \"repairstatus\": 0,\n" +
                    "      \"repairtime\": \"" + ArmsUtils.getDataTime("yyyy-MM-dd HH:mm:ss") + "\",\n" +
                    "      \"picId\": 0,\n" +
                    "      \"Num\": " + weiXiuShuLiang + ",\n" +
                    "      \"Pictures\": [\n" +
                    "        {\n" +
                    "          \"PictureId\": 0,\n" +
                    "          \"PictureExtension\": \"jpg\",\n" +
                    "          \"Picture\": \"" + mGuiHuanYuWeiXiuPic + "\"\n" +
                    "        }\n" +
                    "      ]\n" +
                    "    }\n" +
                    "";
        }
        String strGuiHuan = "";
        if (Double.parseDouble((guiHuanShuLiang.length() > 0 ? guiHuanShuLiang : "0")) > 0) {
            strGuiHuan += "\n" +
                    "    {\n" +
                    "      \"rid\": " + "" + ",\n" +
                    "      \"mid\": " + itemData.getMid() + ",\n" +
                    "      \"oid\": " + itemData.getOid() + ",\n" +
                    "      \"spid\": " + itemData.getSpid() + ",\n" +
                    "      \"picId\": 0,\n" +
                    "      \"returnuserid\": " + mSharedPreferencesHelper.getString(BaseConstants.UID) + ",\n" +
                    "      \"ReturnNum\": " + guiHuanShuLiang + ",\n" +
                    "      \"returntime\": \"" + ArmsUtils.getDataTime("yyyy-MM-dd HH:mm:ss") + "\",\n" +
                    "      \"Pictures\": [\n" +
                    "        {\n" +
                    "          \"PictureId\": 0,\n" +
                    "          \"PictureExtension\": \"jpg\",\n" +
                    "          \"Picture\": \"" + mGuiHuanYuWeiXiuPic + "\"\n" +
                    "        }\n" +
                    "      ]\n" +
                    "    }\n" +
                    "";
        }

        String jsonData = "{\n" +
                "  \"repairdata\": [\n" +
                strWeiXiu +
                "  ],\n" +
                "  \"returndata\": [\n" +
                strGuiHuan +
                "  ]\n" +
                "}";
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), jsonData);

        mPresenter.returnRepair(body);
    }

    @Override
    public void repairGongJuDataSuccess(RepairGongJu entityList) {
        showMessage(entityList.getMessage());
        if (entityList.getCode().equals("200")) {
            mWeiXiuPic = "";
            clearData();

            getLiaoCheng_GongQiJu_GuiHuanCaoZuoList();
        }
    }

    @Override
    public void returnRepairDataSuccess(ReturnRepair entityList) {
        showMessage(entityList.getMessage());
        if (entityList.getCode().equals("200")) {
            mGuiHuanYuWeiXiuPic = "";
            clearData();

            getLiaoCheng_GongQiJu_GuiHuanCaoZuoList();
        }
    }

    private void toScanQRCodeActivity() {
        Intent openCameraIntent = new Intent(this, LiaoCheng_GongQiJu_ScanActivity.class);
        mSharedPreferencesHelper.putInt(SCAN_REQUEST_CODE, 101);
        startActivityForResult(openCameraIntent, 101);
    }
}
